<script lang="ts" setup>
defineProps<{
  items: Array<{title: string; key: string}>
  data: Array<any>
}>()

// TODO: 点击事件外传
const emit = defineEmits(['click'])

function handleClick(row: any) {
  emit('click', row)
}
</script>

<template>
<div class="table">
  <div class="table-header">
    <div v-for="item in items" :key="item.key" class="table-header-item">{{ item.title }}</div>
  </div>
  <div class="table-body hidden-scrollbar">
    <div class="table-row" v-for="(dataItem, index) in data" :key="index" @click="handleClick(dataItem)">

      <div v-for="(item) in items" :key="item.key" class="table-row-cell text-ellipsis" :title="dataItem[item.key]">{{ dataItem[item.key] }}</div>
    </div>
  </div>
</div>
</template>

<style lang="scss" scoped>
.table {
  width: 100%;
  color: #FFFFFF;

  &-header {
    display: flex;
    justify-content: space-around;
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 1px;

    &-item {
      height: 28px;
      padding: 0 8px;
      flex: 1;
      text-align: center;
      font-family: Source Han Sans CN;
      font-size: 14px;
      font-weight: bold;
      line-height: 28px;
      letter-spacing: normal;
      color: #FFFFFF;
      background: rgba(7, 47, 95, 0.3);
      margin-right: 1px;

      &:last-child {
        margin: 0;
      }
    }
  }

  &-body {
    max-height: 216px; /* Adjust as needed */
    overflow-y: auto;
  }

  &-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    margin-bottom: 1px;
    cursor: pointer;
    user-select: none;

    &:last-child {
      margin: 0;
    }

    &-cell {
      height: 30px;
      padding: 0 8px;
      flex: 1;
      text-align: center;
      font-family: Source Han Sans CN;
      font-size: 14px;
      font-weight: normal;
      line-height: 30px;
      letter-spacing: normal;
      color: #FFFFFF;
      margin-right: 1px;
      background: rgba(7, 47, 95, 0.3);
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      user-select: none;

      &:last-child {
        margin: 0;
      }
    }
  }
}
</style>